/**
 * 申请试用帐号服务
 */
angular
.module('myApp')
.factory('applyManager', function($http, $q) {
  return {
    createPost: function(name, mobile, location) {

      var params = {
        user_name: name,
        mobile: mobile
      }

      if (angular.isDefined(location)) {
        var segments = location.split(' ');
        params['province'] = segments[0];
        params['city'] = segments[1];
        params['area'] = segments[2];
      }

      var def = $q.defer();

      $http.post('/apply/trial', params)
        .then(function(response) {
          (response.data.code === 200)
            ? def.resolve(response.data.data)
            : def.reject(response.data.data);
        }, function(response) {
          def.reject({msg: response.status+': '+response.statusText});
        });

      return def.promise;
    }
  }
});
